<?PHP
include_once "src/controller/blmanagement/UserAccountManagement.php";
include_once "src/controller/dbmanagement/EventDBManagement.php";
include_once "src/controller/blmanagement/EventManagement.php";
include_once "src/model/Event.php";
include_once "src/model/User.php";
try {
    $event = new Event();
    $user= UserAccountManagement::getUserByEmail("sono@gmail.com");
    $userNo = $user->getUserId();
    echo "Add a new Record where:\n";
    $event->setApproval(TRUE);
    $event->setEventName("Gathering");
    $event->setLocation("MCS");
    $event->setEventDate('2010-04-13 13:00:00');
    $event->setDescription("birthday");
    $event->setUserId($userNo);
    echo "approval = ".$event->getApproval()."\n";
    echo "Event Name = ".$event->getEventName()."\n";
    echo "Location = ".$event->getLocation()."\n";
    echo "Event Date = ".$event->getEventDate()."\n";
    echo "Description = ".$event->getDescription()."\n";
    echo "User Id = ".$event->getUserId()."\n";
    if (EventManagement::addEvent($event))
        echo "Added...event\n\n";
    else
        echo "event not Added\n\n";

    $eventArray =EventManagement::getAllEvents();
    foreach($eventArray as $event) {
        $eventID1 = $event->getEventID();
        echo "Event Id = ".$event->getEventID()."\n";
        echo "Description = ".$event->getDescription()."\n";
        echo "Event Name = ".$event->getEventName()."\n";
        echo "Location = ".$event->getLocation()."\n";
        echo "Event Date = ".$event->getEventDate()."\n";
    }
    echo"\n";


    echo "updating a new Record with:\n";
    $event ->setDescription("Conference");
    $event->setEventName("Boring Meeting");
    $event->setLocation("Nueces");
    $event->setApproval(FALSE);
    $event->setEventDate('2010-06-13 12:05:00');
    echo "Event Id = ".$event->getEventID()."\n";
    echo "Description = ".$event->getDescription()."\n";
    echo "Event Name = ".$event->getEventName()."\n";
    echo "Location = ".$event->getLocation()."\n";
    echo "Event Date = ".$event->getEventDate()."\n\n";
    EventManagement::updateEvent($event);
    echo"\n";

echo "getting Record with Id $eventID1.\n";
     $event= EventManagement::getEventByID($eventID1);
      echo "Event Id = ".$event->getEventID()."\n";
    echo "Description = ".$event->getDescription()."\n";
    echo "Event Name = ".$event->getEventName()."\n";
    echo "Location = ".$event->getLocation()."\n";
    echo "Event Date = ".$event->getEventDate()."\n\n";

    $event1 = new Event();
    echo "Add a newer Record where\n";
    $event1->setApproval(FALSE);
    echo "approval = ".$event1->getApproval()."\n";
    $event1->setEventName("Meeting");
    echo "Event Name = ".$event1->getEventName()."\n";
    $event1->setLocation("Derrick");
    echo "Location = ".$event1->getLocation()."\n";
    $event1->setEventDate('2010-05-13 12:05:00');
    echo "Event Date = ".$event1->getEventDate()."\n";
    $event1->setDescription("work");
    echo "Description = ".$event1->getDescription()."\n";
    $event1->setUserId($userNo);
    echo "User Id = ".$event1->getUserId()."\n";
    if (EventManagement::addEvent($event1))
        echo "Added...event\n\n";
    else
        echo "event not Added\n\n";

    echo "Retrieving all existing Events.\n";
    $eventArray =EventManagement::getAllEvents();
    foreach($eventArray as $event) {
        echo "Event Id = ".$event->getEventID()."\n";
        echo "Description = ".$event->getDescription()."\n";
        echo "Event Name = ".$event->getEventName()."\n";
        echo "Location = ".$event->getLocation()."\n";
        echo "Event Date = ".$event->getEventDate()."\n\n";
    }


    echo "Delete an existing Record \n";
    $eventId=$event->getEventID();
    if (EventManagement::removeEvent($eventId))
        echo "Event #$eventId deleted...event\n";
    else
        echo "Event #$eventId does not exist\n";

    echo "Retrieving all existing Events.\n";
    $eventArray =EventManagement::getAllEvents();
    foreach($eventArray as $event) {
        echo "Event Id = ".$event->getEventID()."\n";
        echo "Description = ".$event->getDescription()."\n";
        echo "Event Name = ".$event->getEventName()."\n";
        echo "Location = ".$event->getLocation()."\n";
        echo "Event Date = ".$event->getEventDate()."\n\n";
    }
    
    echo "Retrieving all existing Events.\n";
    $eventArray =EventManagement::getAllEvents();
    foreach($eventArray as $event) {
        $eventId = $event->getEventID();
        if (EventManagement::removeEvent($eventId))
            echo "Event #$eventId deleted...event\n";
        else
            echo "Event #$eventId does not exist\n";
        
    }
}
catch (DBException $e) {
    echo $e;
}
catch (DBConnectionException $e) {
    echo $e;
}

?>

